package com.gaoxin.api.service.feeservice;

import java.util.Calendar;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gaoxin.api.dao.feedao.FinancialTargetDao;
import com.gaoxin.api.entity.feeentity.FinancialTarget;

/**
 * 统计缴费数据
 * @author mx
 *
 */
@Service
public class FinancialTargetService {
	
	@Autowired
	private FinancialTargetDao financialTargetDao;
	
	/**
	 * 统计缴费数据
	 * @param financialTarget
	 * @return
	 */
	public FinancialTarget queryFinanceNumber(FinancialTarget financialTarget){
		FinancialTarget entity = new FinancialTarget();
		//查询学费变更前总金额，应交学费总人数
		FinancialTarget selectTuitionBefore = financialTargetDao.selectTuitionBefore(financialTarget);
		//设置总人数
		entity.setTuitionPep(selectTuitionBefore.getTuitionPep());
		//查询变更项变更前总金额，变更项变更后总金额
		FinancialTarget selectChangeMoney = financialTargetDao.selectChangeMoney(financialTarget);
		//设置总钱数
		entity.setTuitionLater(selectTuitionBefore.getTuitionBefore()-selectChangeMoney.getChangeBMoney()+selectChangeMoney.getChangeLMoney());
		//查询已交总金额，已交金额总人数
		FinancialTarget selectImburseMoney = financialTargetDao.selectImburseMoney(financialTarget);
		//设置已交总钱数
		entity.setImburseMoney(selectImburseMoney.getImburseMoney());
		//设置已交总人数
		entity.setImbursePep(selectImburseMoney.getImbursePep());
		//设置欠费总人数
		entity.setArrearsPep(selectTuitionBefore.getTuitionPep()-selectImburseMoney.getImbursePep());
		//设置欠费总钱数
		entity.setArrearsMoney(entity.getTuitionLater()-selectImburseMoney.getImburseMoney());
		//查询缓交总金额，缓交金额总人数
		FinancialTarget selectDeferMoney = financialTargetDao.selectDeferMoney(financialTarget);
		//设置缓交总金额
		entity.setDeferMoney(selectDeferMoney.getDeferMoney());
		//设置缓交总人数
		entity.setDeferPep(selectDeferMoney.getDeferPep());
		//查询贷款总金额，贷款金额总人数
		FinancialTarget selectLoanMoney = financialTargetDao.selectLoanMoney(financialTarget);
		//设置贷款总金额
		entity.setLoanMoney(selectLoanMoney.getLoanMoney());
		//设置贷款金额总人数
		entity.setLoanPep(selectLoanMoney.getLoanPep());
		//查询减免总金额，减免金额总人数
		FinancialTarget selectDerateMoney = financialTargetDao.selectDerateMoney(financialTarget);
		//设置减免总金额
		entity.setDerateMoney(selectDerateMoney.getDerateMoney());
		//设置减免总人数
		entity.setDeratePep(selectDerateMoney.getDeratePep());
		return entity;
	   }
	
	/**
	 * 显示学年
	 * @return
	 */
	public String[] getYear(){
		Calendar cal = Calendar.getInstance();
		int year = cal.get(Calendar.YEAR);
		String[] num = new String[17];
		num[0] = String.valueOf(year-6) + "—" + String.valueOf(year-5);
		num[1] = String.valueOf(year-5) + "—" + String.valueOf(year-4);
		num[2] = String.valueOf(year-4) + "—" + String.valueOf(year-3);
		num[3] = String.valueOf(year-3) + "—" + String.valueOf(year-2);
		num[4] = String.valueOf(year-2) + "—" + String.valueOf(year-1);
		num[5] = String.valueOf(year-1) + "—" + String.valueOf(year);
		num[6] = String.valueOf(year) + "—" + String.valueOf(year+1);
		num[7] = String.valueOf(year+1) + "—" + String.valueOf(year+2);
		num[8] = String.valueOf(year+2) + "—" + String.valueOf(year+3);
		num[9] = String.valueOf(year+3) + "—" + String.valueOf(year+4);
		num[10] = String.valueOf(year+4) + "—" + String.valueOf(year+5);
		num[11] = String.valueOf(year+5) + "—" + String.valueOf(year+6);
		num[12] = String.valueOf(year+6) + "—" + String.valueOf(year+7);
		num[13] = String.valueOf(year+7) + "—" + String.valueOf(year+8);
		num[14] = String.valueOf(year+8) + "—" + String.valueOf(year+9);
		num[15] = String.valueOf(year+9) + "—" + String.valueOf(year+10);
		num[16] = String.valueOf(year+10) + "—" + String.valueOf(year+11);
		return num;
	}
}
